package kr.pe.johnkim.pushchat.mobile.dao;

import kr.pe.johnkim.pushchat.mobile.domain.PushChatAnnouncement;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author : John_Kim <cale9797@gmail.com>
 * @date : 13. 9. 13.
 */
@Repository
public class PushChatAnnouncementDaoImpl extends SqlSessionDaoSupport implements PushChatAnnouncementDao {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(PushChatAnnouncementDaoImpl.class);

    /**
     * 공지사항을 등록 한다.
     *
     * @param pushChatAnnouncement
     */
    @Override
    public void registerAnnouncement(PushChatAnnouncement pushChatAnnouncement) {
        logger.info("registerAnnouncement");
        this.getSqlSession().insert("PUSHCHAT_ANNOUNCEMENT.registerAnnouncement", pushChatAnnouncement);
    }

    /**
     * 공지사항 목록을 가져 온다.
     *
     * @param pushChatAnnouncement
     * @return
     */
    @Override
    public List<PushChatAnnouncement> selectAnnouncementList(PushChatAnnouncement pushChatAnnouncement) {
        logger.info("selectAnnouncementList");
        return this.getSqlSession().selectList("PUSHCHAT_ANNOUNCEMENT.selectAnnouncementList", pushChatAnnouncement);
    }

    /**
     * 공지사항 상세 내용을 가져 온다.
     *
     * @param pushChatAnnouncement
     * @return
     */
    @Override
    public PushChatAnnouncement selectAnnouncementInformation(PushChatAnnouncement pushChatAnnouncement) {
        logger.info("selectAnnouncementInformation");
        return (PushChatAnnouncement)this.getSqlSession().selectOne("PUSHCHAT_ANNOUNCEMENT.selectAnnouncementInformation", pushChatAnnouncement);
    }

    /**
     * 공지사항을 수정 한다.
     *
     * @param pushChatAnnouncement
     */
    @Override
    public void updateAnnouncement(PushChatAnnouncement pushChatAnnouncement) {
        logger.info("updateAnnouncement");
        this.getSqlSession().update("PUSHCHAT_ANNOUNCEMENT.updateAnnouncement", pushChatAnnouncement);
    }

    /**
     * 공지사항을 비활성화 한다.
     *
     * @param pushChatAnnouncement
     */
    @Override
    public void updateDeactivateAnnouncement(PushChatAnnouncement pushChatAnnouncement) {
        logger.info("updateDeactivateAnnouncement");
        this.getSqlSession().update("PUSHCHAT_ANNOUNCEMENT.updateDeactivateAnnouncement", pushChatAnnouncement);
    }
}
